home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / unix / cshel401 / part03 < prev    next >
Internet Message Format  |  1990-03-13  |  22KB

  1. Path: xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i105: CShell 4.01A - alternative command interface, Part03/04
  5. Message-ID: <11772@xanth.cs.odu.edu>
  6. Date: 13 Mar 90 00:45:25 GMT
  7. Sender: news@cs.odu.edu
  8. Reply-To: page@Eng.Sun.COM (Bob Page)
  9. Lines: 796
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11. X-Mail-Submissions-To: Amiga@cs.odu.edu
  12. X-Post-Discussions-To: comp.sys.amiga
  13.  
  14. Submitted-by: page@Eng.Sun.COM (Bob Page)
  15. Posting-number: Volume 90, Issue 105
  16. Archive-name: unix/cshell-4.01a/part03
  17.  
  18. #!/bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 3 (of 4)."
  25. # Contents:  src/execom.c
  26. # Wrapped by tadguy@xanth on Mon Mar 12 19:44:29 1990
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'src/execom.c' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'src/execom.c'\"
  30. else
  31. echo shar: Extracting \"'src/execom.c'\" \(19272 characters\)
  32. sed "s/^X//" >'src/execom.c' <<'END_OF_FILE'
  33. X/*
  34. X * EXECOM.C
  35. X *
  36. X * Matthew Dillon, 10 August 1986
  37. X *    Finally re-written.
  38. X *
  39. X * Version 2.07M by Steve Drew 10-Sep-87
  40. X *
  41. X * Version 4.01A by Carlo Borreo & Cesare Dieni 17-Feb-90
  42. X *
  43. X */
  44. X
  45. X#define F_EXACT 0
  46. X#define F_ABBR  1
  47. X
  48. X#define ST_COND   0x01
  49. X#define ST_NORED  0x02
  50. X#define ST_NOEXP  0x04
  51. X#define ST_AV     0x08 /* delimit args within a variable */
  52. X
  53. Xint has_wild = 0;                 /* set if any arg has wild card */
  54. X
  55. Xstruct COMMAND {
  56. X    int (*func)();
  57. X    short minargs;
  58. X    short stat;
  59. X    int val;
  60. X    char *name;
  61. X};
  62. X
  63. Xextern char *format_insert_string();
  64. Xextern char *mpush(), *exarg();
  65. X
  66. Xextern int do_basename(), do_tackon();
  67. Xextern int do_fltupper(), do_fltlower();
  68. Xextern int do_strleft(), do_strright(), do_strmid(), do_strlen();
  69. Xextern int do_fornum(), do_forline(), do_exec();
  70. Xextern int do_diskchange(), do_stack(), do_fault(), do_path(), do_pri();
  71. Xextern int do_rpn(), do_resident(), do_truerun(), do_aset(), do_howmany();
  72. Xextern int do_open(), do_close(), do_fileslist(), do_htype();
  73. Xextern int do_run(), do_number(), do_assign(), do_join();
  74. Xextern int do_quit(), do_set_var(), do_unset_var();
  75. Xextern int do_echo(), do_source(), do_mv(), do_addbuffers();
  76. Xextern int do_cd(), do_pwd(), do_rm(), do_mkdir(), do_history();
  77. Xextern int do_mem(), do_cat(), do_dir(), do_info(), do_inc();
  78. Xextern int do_foreach(), do_return(), do_if(), do_label(), do_goto();
  79. Xextern int do_input(), do_ver(), do_sleep(), do_help();
  80. Xextern int do_strhead(), do_strtail(), do_relabel();
  81. Xextern int do_copy(), do_date(), do_protect(), do_ps();
  82. Xextern int do_forever(), do_abortline(), do_strings(), do_touch();
  83. Xextern int do_window(), do_search(), do_filenote(), do_rxrec(), do_rxsend();
  84. Xchar *push_cpy();
  85. X
  86. Xstatic struct COMMAND Command[] = {
  87. Xdo_run,        0, ST_AV,    0,    "\001",   /* may call do_source */
  88. Xdo_abortline,    0, 0,        0,    "abortline",
  89. Xdo_addbuffers,    2, 0,        0,    "addbuffers",
  90. Xdo_set_var,    0, 0, LEVEL_ALIAS,    "alias",  /* uses avline */
  91. Xdo_aset,    1, 0,        0,    "aset",
  92. Xdo_assign,    0, 0,        0,    "assign",
  93. Xdo_basename,    2, 0,        0,    "basename",
  94. Xdo_cat,        0, 0,        0,    "cat",
  95. Xdo_cd,        0, 0,        0,    "cd",
  96. Xdo_close,    0, 0,        0,    "close",
  97. Xdo_copy,    1, 0,        0,    "copy",
  98. Xdo_copy,    1, 0,        0,    "cp",
  99. Xdo_date,    0, 0,        0,    "date",
  100. Xdo_inc,        1, 0,        -1,    "dec",
  101. Xdo_rm,        0, 0,        0,    "delete",
  102. Xdo_dir,        0, ST_NOEXP,    0,    "dir",
  103. Xdo_diskchange,    1, 0,        0,    "diskchange",
  104. Xdo_echo,    0, 0,        0,    "echo", /* uses avline */
  105. Xdo_if,        0, ST_COND,    1,    "else",
  106. Xdo_if,        0, ST_COND,    2,    "endif",
  107. Xdo_exec,    1, 0,        0,    "exec",
  108. Xdo_fault,    1, 0,        0,    "fault",
  109. Xdo_filenote,    2, 0,        0,    "filenote",
  110. Xdo_fileslist,    0, 0,        0,    "flist",
  111. Xdo_fltlower,    0, 0,        0,    "fltlower",
  112. Xdo_fltupper,    0, 0,        0,    "fltupper",
  113. Xdo_foreach,    3, ST_NORED,    0,    "foreach",
  114. Xdo_forever,    1, ST_NORED,    0,    "forever",
  115. Xdo_forline,    3, ST_NORED,    0,    "forline",
  116. Xdo_fornum,    4, ST_NORED,    0,    "fornum",
  117. Xdo_goto,    1, 0,        0,    "goto",
  118. Xdo_help,    0, 0,        0,    "help",
  119. Xdo_history,    0, 0,        0,    "history",
  120. Xdo_howmany,    0, 0,        0,    "howmany",
  121. Xdo_htype,    1, 0,        0,    "htype",
  122. Xdo_if,        1, ST_COND|ST_NORED,0,    "if",
  123. Xdo_inc,        1, 0,        1,    "inc",
  124. Xdo_info,    0, 0,        0,    "info",
  125. Xdo_input,    1, 0,        0,    "input",
  126. Xdo_join,    2, 0,        1,    "join",
  127. Xdo_label,    1, ST_COND,    0,    "label",
  128. Xdo_dir,        0, ST_NOEXP,    0,    "ls",
  129. Xdo_mkdir,    0, 0,        0,    "md",
  130. Xdo_mem,        0, 0,        0,    "mem",
  131. Xdo_mkdir,    0, 0,        0,    "mkdir",
  132. Xdo_mv,        2, 0,        0,    "mv",
  133. Xdo_open,    3, 0,        0,    "open",
  134. Xdo_path,    0, 0,        0,    "path",
  135. Xdo_pri,        2, 0,        0,    "pri",
  136. Xdo_protect,    2, 0,        0,    "protect",
  137. Xdo_ps,        0, 0,        0,    "ps",
  138. Xdo_pwd,        0, 0,        0,    "pwd",
  139. Xdo_quit,    0, ST_NORED,    0,    "quit",
  140. Xdo_truerun,    1, ST_NORED,    1,    "rback",
  141. Xdo_mv,        2, 0,        0,    "rename",
  142. Xdo_relabel,    2, 0,        0,    "relabel",
  143. Xdo_resident,    0, 0,        0,    "resident",
  144. Xdo_return,    0, 0,        0,    "return",
  145. Xdo_rm,        0, 0,        0,    "rm",
  146. Xdo_rpn,        0, ST_NOEXP,    0,    "rpn",
  147. Xdo_rxrec,    1, 0,        0,    "rxrec",
  148. Xdo_rxsend,    2, 0,        0,    "rxsend",
  149. Xdo_truerun,    1, ST_NORED,    0,    "run",
  150. Xdo_search,    2, 0,        0,    "search",
  151. Xdo_set_var,    0, ST_AV, LEVEL_SET,    "set",
  152. Xdo_sleep,    0, 0,        0,    "sleep",
  153. Xdo_source,    0, ST_NORED|ST_AV, 0,    "source", /* uses avline */
  154. Xdo_stack,    0, 0,        0,    "stack",
  155. Xdo_strhead,    3, 0,        0,    "strhead",
  156. Xdo_strings,    1, 0,        0,    "strings",
  157. Xdo_strleft,    3, 0,        0,    "strleft",
  158. Xdo_strlen,    2, 0,        0,    "strlen",
  159. Xdo_strmid,    3, 0,        0,    "strmid",
  160. Xdo_strright,    3, 0,        0,    "strright",
  161. Xdo_strtail,    3, 0,        0,    "strtail",
  162. Xdo_tackon,    3, 0,        0,    "tackon",
  163. Xdo_touch,    0, 0,        0,    "touch",
  164. Xdo_cat,        0, 0,        0,    "type",
  165. Xdo_unset_var,    0, 0, LEVEL_ALIAS,    "unalias",
  166. Xdo_unset_var,    0, 0, LEVEL_SET  ,    "unset",
  167. Xdo_ver,        0, 0,        0,    "version",
  168. Xdo_window,    0, ST_NOEXP,    0,    "window",
  169. X'\0',        0, 0,        0,    NULL
  170. X};
  171. X
  172. Xstatic unsigned char elast;        /* last end delimeter */
  173. Xstatic char Cin_ispipe, Cout_ispipe;
  174. X
  175. Xexec_command(base)
  176. Xchar *base;
  177. X{
  178. Xregister char *scr;
  179. Xchar buf[32];
  180. X
  181. Xif (!H_stack) {
  182. X    add_history(base);
  183. X    sprintf(buf, "%d", H_tail_base + H_len);
  184. X    set_var(LEVEL_SET, v_histnum, buf);
  185. X    }
  186. Xscr = malloc((strlen(base) << 2) + 2);
  187. Xpreformat(base, scr);
  188. Xreturn (fcomm(scr, 1) ? -1 : 1);
  189. X}
  190. X
  191. Xisalphanum(c)
  192. Xregister char c;
  193. X{
  194. Xreturn (
  195. X    (c >= '0' && c <= '9') ||
  196. X    (c >= 'a' && c <= 'z') ||
  197. X    (c >= 'A' && c <= 'Z') ||
  198. X    (c == '_')
  199. X    );
  200. X}
  201. X
  202. Xpreformat(s, d)
  203. Xregister char *s, *d;
  204. X{
  205. Xregister int si, di, qm;
  206. X
  207. Xsi = di = qm = 0;
  208. Xwhile (s[si] == ' ' || s[si] == 9) ++si;
  209. Xwhile (s[si]) {
  210. X    if (qm && s[si] != '\"' && s[si] != '\\') {
  211. X        d[di++] = s[si++] | 0x80;
  212. X        continue;
  213. X        }
  214. X    switch (s[si]) {
  215. X        case ' ':
  216. X        case 9:
  217. X            d[di++] = ' ';
  218. X            while (s[si] == ' ' || s[si] == 9) ++si;
  219. X            if (s[si] == 0 || s[si] == '|' || s[si] == ';') --di;
  220. X            break;
  221. X        case '*':
  222. X        case '?':
  223. X            d[di++] = 0x80;
  224. X        case '!':
  225. X            d[di++] = s[si++];
  226. X            break;
  227. X        case '#':
  228. X            d[di++] = '\0';
  229. X            while (s[si]) ++si;
  230. X            break;
  231. X        case ';':
  232. X        case '|':
  233. X            d[di++] = s[si++];
  234. X            while (s[si] == ' ' || s[si] == 9) ++si;
  235. X            break;
  236. X        case '\\':
  237. X            d[di++] = s[++si] | 0x80;
  238. X            if (s[si]) ++si;
  239. X            break;
  240. X        case '\"':
  241. X            qm = 1 - qm;
  242. X            ++si;
  243. X            break;
  244. X        case '^':
  245. X            d[di++] = s[++si] & 0x1F;
  246. X            if (s[si]) ++si;
  247. X            break;
  248. X        case '$': /* search end of var name and place false space */
  249. X            d[di++] = 0x80;
  250. X            d[di++] = s[si++];
  251. X            while (isalphanum(s[si])) d[di++] = s[si++];
  252. X            d[di++] = 0x80;
  253. X            break;
  254. X        default:
  255. X            d[di++] = s[si++];
  256. X            break;
  257. X        }
  258. X    }
  259. Xd[di++]=0;
  260. Xd[di]=0;
  261. Xif (debug) fprintf (stderr,"PREFORMAT: %d :%s:\n", strlen(d), d);
  262. X}
  263. X
  264. Xextern BPTR extOpen();
  265. X
  266. X/*
  267. X * process formatted string.  ' ' is the delimeter.
  268. X *
  269. X *    0: check '\0': no more, stop, done.
  270. X *    1: check $.     if so, extract, format, insert
  271. X *    2: check alias. if so, extract, format, insert. goto 1
  272. X *    3: check history or substitution, extract, format, insert. goto 1
  273. X *
  274. X *    4: assume first element now internal or disk based command.
  275. X *
  276. X *    5: extract each ' ' or 0x80 delimited argument and process, placing
  277. X *       in av[] list (except 0x80 args appended).  check in order:
  278. X *
  279. X *             '$'         insert string straight
  280. X *             '>'         setup stdout
  281. X *             '>>'        setup stdout flag for append
  282. X *             '<'         setup stdin
  283. X *             '*' or '?'  do directory search and insert as separate args.
  284. X *
  285. X *             ';' 0 '|'   end of command.  if '|' setup stdout
  286. X *                          -execute command, fix stdin and out (|) sets
  287. X *                           up stdin for next guy.
  288. X */
  289. X
  290. X
  291. Xfcomm(str, freeok)
  292. Xregister char *str;
  293. X{
  294. X   static int alias_count;
  295. X   int p_alias_count = 0;
  296. X   char *istr;
  297. X   char *nextstr;
  298. X   char *command;
  299. X   char *pend_alias = NULL;
  300. X   char err = 0;
  301. X   has_wild = 0;
  302. X
  303. X   ++alias_count;
  304. X
  305. X   mpush_base();
  306. X   if (*str == 0)
  307. X      goto done1;
  308. Xstep1:
  309. X   if (alias_count == MAXALIAS || ++p_alias_count == MAXALIAS) {
  310. X      fprintf(stderr,"Alias Loop\n");
  311. X      err = 20;
  312. X      goto done1;
  313. X   }
  314. X/*
  315. X   if (str[1] == '$') {
  316. X      if (istr = get_var (LEVEL_SET, str + 2))
  317. X         str = format_insert_string(str, istr, &freeok);
  318. X   }
  319. X*/
  320. X   istr = NULL;
  321. X   if (*(unsigned char *)str < 0x80)
  322. X      istr = get_var (LEVEL_ALIAS, str);  /* only if not \command */
  323. X   *str &= 0x7F;                          /* remove \ teltail     */
  324. X   if (istr) {
  325. X      if (*istr == '%') {
  326. X         pend_alias = istr;
  327. X      } else {
  328. X         str = format_insert_string(str, istr, &freeok);
  329. X         goto step1;
  330. X      }
  331. X   }
  332. X   if (*str == '!') {
  333. X      char *p, c;                     /* fix to allow !cmd1;!cmd2 */
  334. X      for(p = str; *p && *p != ';' ; ++p);
  335. X      c = *p;
  336. X      *p = '\0';
  337. X      istr = get_history(str);
  338. X      *p = c;
  339. X      replace_head(istr);
  340. X      str = format_insert_string(str, istr, &freeok);
  341. X      goto step1;
  342. X   }
  343. X   nextstr = str;
  344. X   command = exarg(&nextstr);
  345. X   if (*command == 0)
  346. X      goto done0;
  347. X   if (pend_alias == 0) {
  348. X      if (cmd_stat(command) & ST_COND)
  349. X         goto skipgood;
  350. X   }
  351. X   if (disable || forward_goto) {
  352. X      while (elast && elast != ';' && elast != '|')
  353. X         exarg(&nextstr);
  354. X      goto done0;
  355. X   }
  356. Xskipgood:
  357. X   {
  358. X      register char *arg, *ptr, *scr;
  359. X      short redir;
  360. X      short doexpand;
  361. X      short cont;
  362. X      short inc;
  363. X
  364. X      ac = 1;
  365. X      av[0] = command;
  366. Xstep5:                                          /* ac = nextac */
  367. X      if (!elast || elast == ';' || elast == '|')
  368. X         goto stepdone;
  369. X
  370. X      av[ac] = '\0';
  371. X      cont = 1;
  372. X      doexpand = redir = inc = 0;
  373. X
  374. X      while (cont && elast) {
  375. X         int cstat = cmd_stat(command);
  376. X
  377. X         ptr = exarg(&nextstr);
  378. X         inc = 1;
  379. X         arg = "";
  380. X         cont = (elast == 0x80);
  381. X         switch (*ptr) {
  382. X         case '<':
  383. X            redir = -2;
  384. X         case '>':
  385. X            if (cstat & (ST_NORED | ST_COND)) {
  386. X                                                        /* don't extract   */
  387. X                redir = 0;                              /* <> stuff if its */
  388. X                arg = ptr;                              /* external cmd.   */
  389. X                break;
  390. X            }
  391. X            ++redir;
  392. X            arg = ptr + 1;
  393. X            if (*arg == '>') {
  394. X               redir = 2;        /* append >> */
  395. X               ++arg;
  396. X            }
  397. X            cont = 1;
  398. X            break;
  399. X         case '$':
  400. X            /* restore args if from set command or pend_alias */
  401. X            if ((arg = get_var(LEVEL_SET, ptr + 1)) != NULL) {
  402. X               if (cstat & ST_COND) {
  403. X                  char *tp;
  404. X                  tp = push_cpy(arg);
  405. X                  arg = tp;
  406. X               }
  407. X               else {
  408. X                  char *pe, sv;
  409. X                  while (pe = index(arg,0xA0)) {
  410. X                     sv = *pe;
  411. X                     *pe = '\0';
  412. X                     av[ac++] = push_cpy(arg);
  413. X                     *pe = sv;
  414. X                     av[ac] = '\0';
  415. X                     arg = pe+1;
  416. X                  }
  417. X               }
  418. X            }
  419. X            else
  420. X               arg = ptr;
  421. X            break;
  422. X         case '*':
  423. X         case '?':
  424. X            if ((cstat & ST_NOEXP) == 0)
  425. X               doexpand = 1;
  426. X            arg = ptr;
  427. X            break;
  428. X         default:
  429. X            arg = ptr;
  430. X            break;
  431. X         }
  432. X
  433. X         /* Append arg to av[ac] */
  434. X
  435. X         for (scr = arg; *scr; ++scr)
  436. X            *scr &= 0x7F;
  437. X         if (av[ac]) {
  438. X            register char *old = av[ac];
  439. X            av[ac] = mpush(strlen(arg)+strlen(av[ac]));
  440. X            strcpy(av[ac], old);
  441. X            strcat(av[ac], arg);
  442. X         } else {
  443. X            av[ac] = push_cpy(arg);
  444. X         }
  445. X         if (elast != 0x80)
  446. X            break;
  447. X      }
  448. X
  449. X      /* process expansion */
  450. X
  451. X      if (doexpand) {
  452. X         char **eav, **ebase;
  453. X         int eac;
  454. X         has_wild = 1;
  455. X         eav = ebase = expand(av[ac], &eac);
  456. X         inc = 0;
  457. X         if (eav) {
  458. X            if (ac + eac + 2 > MAXAV) {
  459. X               ierror (NULL, 506);
  460. X               err = 1;
  461. X            } else {
  462. X               QuickSort(eav, eac);
  463. X               for (; eac; --eac, ++eav)
  464. X                  av[ac++] = push_cpy(*eav);
  465. X            }
  466. X            free_expand (ebase);
  467. X         }
  468. X      }
  469. X
  470. X      /* process redirection  */
  471. X
  472. X      if (redir && !err) {
  473. X         register char *file = (doexpand) ? av[--ac] : av[ac];
  474. X
  475. X         if (redir < 0)
  476. X            Cin_name = file;
  477. X         else {
  478. X            Cout_name = file;
  479. X            Cout_append = (redir == 2);
  480. X         }
  481. X         inc = 0;
  482. X      }
  483. X
  484. X      /* check elast for space */
  485. X
  486. X      if (inc) {
  487. X         ++ac;
  488. X         if (ac + 2 > MAXAV) {
  489. X            ierror (NULL, 506);
  490. X            err = 1;                /* error condition */
  491. X            elast = 0;              /* don't process any more arguemnts */
  492. X         }
  493. X      }
  494. X      if (elast == ' ')
  495. X         goto step5;
  496. X   }
  497. Xstepdone:
  498. X   av[ac] = '\0';
  499. X
  500. X   /* process pipes via files */
  501. X
  502. X   if (elast == '|' && !err) {
  503. X      static int which;             /* 0 or 1 in case of multiple pipes */
  504. X      which = 1 - which;
  505. X      Cout_name = (which) ? Pipe1 : Pipe2;
  506. X      Cout_ispipe = 1;
  507. X   }
  508. X
  509. X
  510. X   if (err)
  511. X      goto done0;
  512. X
  513. X   {
  514. X      register int i;
  515. X      char save_elast;
  516. X      char *compile_av();
  517. X      register char *avline;
  518. X      unsigned char delim = ' ';
  519. X
  520. X      save_elast = elast;
  521. X      if (pend_alias || (cmd_stat(command) & ST_AV))
  522. X         delim = 0xA0;
  523. X      avline = compile_av(av,((pend_alias) ? 1 : 0), ac, delim, 0);
  524. X
  525. X      if (pend_alias) {                               /* special % alias */
  526. X         register char *ptr, *scr;
  527. X         for (ptr = pend_alias; *ptr && *ptr != ' '; ++ptr);
  528. X         set_var (LEVEL_SET, pend_alias + 1, avline);
  529. X         free (avline);
  530. X
  531. X         scr = malloc((strlen(ptr) << 2) + 2);
  532. X         preformat (ptr, scr);
  533. X         fcomm (scr, 1);
  534. X         unset_var (LEVEL_SET, pend_alias + 1);
  535. X      } else {                                        /* normal command  */
  536. X         register int ccno;
  537. X         long  oldcin  = Myprocess->pr_CIS;
  538. X         long  oldcout = Myprocess->pr_COS;
  539. X         char *Cin_buf;
  540. X         struct FileHandle *ci;
  541. X         long oldbuf;
  542. X
  543. X         fflush(stdout);
  544. X         ccno = find_command (command);
  545. X         if ((Command[ccno].stat & (ST_NORED | ST_COND)) == 0) {
  546. X            if (Cin_name) {
  547. X               if ((Cin = (long)extOpen(Cin_name,1005L)) == 0L) {
  548. X                  ierror (NULL, 504);
  549. X                  err = 1;
  550. X                  Cin_name = '\0';
  551. X               } else {
  552. X                  Myprocess->pr_CIS = _devtab[stdin->_unit].fd = Cin;
  553. X                  ci = (struct FileHandle *)(((long)Cin)<<2);
  554. X                  Cin_buf = (char *)AllocMem(202L, MEMF_PUBLIC);
  555. X                  oldbuf = ci->fh_Buf;
  556. X                  if (ci->fh_Buf == 0) /* fexec expects a CIS buffer */
  557. X                     ci->fh_Buf = (long)Cin_buf>>2;
  558. X               }
  559. X            }
  560. X            if (Cout_name) {
  561. X               if (Cout_append && (Cout =(long)extOpen(Cout_name, 1005L)) ) {
  562. X                     Seek(Cout, 0L, 1L);
  563. X               } else {
  564. X                  Cout = (long)extOpen(Cout_name,1006L);
  565. X               }
  566. X               if (Cout == NULL) {
  567. X                  err = 1;
  568. X                  ierror (NULL, 504);
  569. X                  Cout_name = '\0';
  570. X                  Cout_append = 0;
  571. X               } else {
  572. X                  Myprocess->pr_COS = _devtab[stdout->_unit].fd = Cout;
  573. X               }
  574. X            }
  575. X         }
  576. X         if (ac < Command[ccno].minargs + 1) {
  577. X            ierror (NULL, 500);
  578. X            err = -1;
  579. X         } else if (!err) {
  580. X            i = (*Command[ccno].func)(avline, Command[ccno].val);
  581. X            if (i < 0)
  582. X               i = 20;
  583. X            err = i;
  584. X         }
  585. X         free (avline);
  586. X         if (E_stack == 0 && Lastresult != err) {
  587. X            Lastresult = err;
  588. X            seterr();
  589. X         }
  590. X         if ((Command[ccno].stat & (ST_NORED | ST_COND)) == 0) {
  591. X            if (Cin_name) {
  592. X               fflush(stdin);
  593. X               clearerr(stdin);
  594. X               ci->fh_Buf = oldbuf;
  595. X               extClose(Cin);
  596. X               FreeMem(Cin_buf, 202L);
  597. X            }
  598. X            if (Cout_name) {
  599. X               fflush(stdout);
  600. X               clearerr(stdout);
  601. X               stdout->_flags &= ~_DIRTY;    /* because of nil: device */
  602. X               extClose(Cout);
  603. X               Cout_append = 0;
  604. X            }
  605. X         }
  606. X         Myprocess->pr_CIS =  _devtab[stdin->_unit].fd  = oldcin;
  607. X         Myprocess->pr_COS =  _devtab[stdout->_unit].fd = oldcout;
  608. X      }
  609. X
  610. X      if (Cin_ispipe && Cin_name)
  611. X         DeleteFile(Cin_name);
  612. X      if (Cout_ispipe) {
  613. X         Cin_name = Cout_name;         /* ok to assign.. static name */
  614. X         Cin_ispipe = 1;
  615. X      } else {
  616. X         Cin_name = '\0';
  617. X      }
  618. X      Cout_name = '\0';
  619. X      Cout_ispipe = 0;
  620. X      elast = save_elast;
  621. X   }
  622. X   mpop_tobase();                      /* free arguments   */
  623. X   mpush_base();                       /* push dummy base  */
  624. X
  625. Xdone0:
  626. X   {
  627. X      char *str;
  628. X      if (err && E_stack == 0) {
  629. X         str = get_var(LEVEL_SET, v_except);
  630. X         if (err >= ((str)?atoi(str):1)) {
  631. X            if (str) {
  632. X               ++H_stack;
  633. X               ++E_stack;
  634. X               exec_command(str);
  635. X               --E_stack;
  636. X               --H_stack;
  637. X            } else {
  638. X               Exec_abortline = 1;
  639. X            }
  640. X         }
  641. X      }
  642. X      if (elast != 0 && Exec_abortline == 0)
  643. X         err = fcomm(nextstr, 0);
  644. X      Exec_abortline = 0;
  645. X      if (Cin_name)
  646. X         DeleteFile(Cin_name);
  647. X      Cin_name = NULL;
  648. X      Cin_ispipe = 0;
  649. X   }
  650. Xdone1:
  651. X   mpop_tobase();
  652. X   if (freeok)
  653. X      free(str);
  654. X   --alias_count;
  655. X   return ((int)err);                  /* TRUE = error occured    */
  656. X}
  657. X
  658. X
  659. Xchar *
  660. Xexarg(ptr)
  661. Xunsigned char **ptr;
  662. X{
  663. X   register unsigned char *end;
  664. X   register unsigned char *start;
  665. X
  666. X   start = end = *ptr;
  667. X   while (*end && *end != 0x80 && *end != ';' && *end != '|' && *end != ' ')
  668. X      ++end;
  669. X   elast = *end;
  670. X   *end = '\0';
  671. X   *ptr = end + 1;
  672. X   return ((char *)start);
  673. X}
  674. X
  675. Xstatic char **Mlist;
  676. X
  677. Xmpush_base()
  678. X{
  679. X   char *str;
  680. X
  681. X   str = malloc(5);
  682. X   *(char ***)str = Mlist;
  683. X   str[4] = 0;
  684. X   Mlist = (char **)str;
  685. X}
  686. X
  687. Xchar *
  688. Xmpush(bytes)
  689. X{
  690. X   char *str;
  691. X
  692. X   str = malloc(6 + bytes + 2);   /* may need extra 2 bytes in do_run() */
  693. X   *(char ***)str = Mlist;
  694. X   str[4] = 1;
  695. X   Mlist = (char **)str;
  696. X   return (str + 5);
  697. X}
  698. X
  699. Xmpop_tobase()
  700. X{
  701. X   register char *next;
  702. X   while (Mlist) {
  703. X      next = *Mlist;
  704. X      if (((char *)Mlist)[4] == 0) {
  705. X         free (Mlist);
  706. X         Mlist = (char **)next;
  707. X         break;
  708. X      }
  709. X      free (Mlist);
  710. X      Mlist = (char **)next;
  711. X   }
  712. X}
  713. X
  714. X
  715. X/*
  716. X * Insert 'from' string in front of 'str' while deleting the
  717. X * first entry in 'str'.  if freeok is set, then 'str' will be
  718. X * free'd
  719. X */
  720. X
  721. Xchar *format_insert_string(str, from, freeok)
  722. Xchar *str;
  723. Xchar *from;
  724. Xint *freeok;
  725. X{
  726. Xregister char *new1, *new2;
  727. Xregister unsigned char *strskip;
  728. Xint len;
  729. X
  730. Xfor (strskip = (unsigned char *)str;
  731. X        *strskip && *strskip != ' ' 
  732. X        && *strskip != ';' && *strskip != '|'
  733. X        && *strskip != 0x80; ++strskip);
  734. Xlen = strlen(from);
  735. Xnew1 = malloc((len << 2) + 2);
  736. Xpreformat(from, new1);
  737. Xlen = strlen(new1) + strlen(strskip);
  738. Xnew2 = malloc(len+2);
  739. Xstrcpy(new2, new1);
  740. Xstrcat(new2, strskip);
  741. Xnew2[len+1] = 0;
  742. Xfree (new1);
  743. Xif (*freeok) free (str);
  744. X*freeok = 1;
  745. Xreturn new2;
  746. X}
  747. X
  748. Xcmd_stat(str)
  749. Xchar *str;
  750. X{
  751. Xreturn(Command[find_command(str)].stat);
  752. X}
  753. X
  754. Xfind_command(str)
  755. Xchar *str;
  756. X{
  757. Xregister unsigned short i;
  758. Xint len = strlen(str);
  759. X
  760. Xfor (i = 0; Command[i].func; ++i)
  761. X    if ( ! strncmp(str, Command[i].name, len)) return (int)i;
  762. Xreturn 0;
  763. X}
  764. X
  765. Xdo_help()
  766. X{
  767. Xregister struct COMMAND *com;
  768. Xint i=0;
  769. X
  770. Xfor (com = &Command[1]; com->func; ++com) {
  771. X    printf ("%-12s", com->name);
  772. X    if (++i % 6 == 0) printf("\n");
  773. X    }
  774. Xprintf("\n");
  775. Xreturn 0;
  776. X}
  777. X
  778. Xchar *push_cpy(s)
  779. Xchar *s;
  780. X{
  781. Xreturn strcpy(mpush(strlen(s)), s);
  782. X}
  783. END_OF_FILE
  784. if test 19272 -ne `wc -c <'src/execom.c'`; then
  785.     echo shar: \"'src/execom.c'\" unpacked with wrong size!
  786. fi
  787. # end of 'src/execom.c'
  788. fi
  789. echo shar: End of archive 3 \(of 4\).
  790. cp /dev/null ark3isdone
  791. MISSING=""
  792. for I in 1 2 3 4 ; do
  793.     if test ! -f ark${I}isdone ; then
  794.     MISSING="${MISSING} ${I}"
  795.     fi
  796. done
  797. if test "${MISSING}" = "" ; then
  798.     echo You have unpacked all 4 archives.
  799.     rm -f ark[1-9]isdone
  800. else
  801.     echo You still need to unpack the following archives:
  802.     echo "        " ${MISSING}
  803. fi
  804. ##  End of shell archive.
  805. exit 0
  806. -- 
  807. Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
  808. Mail comments to the moderator at <amiga-request@cs.odu.edu>.
  809. Post requests for sources, and general discussion to comp.sys.amiga.
  810.